package com.example.mapreduce.partitionerandwritableComparable;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;

/**
 * Created with IntelliJ IDEA.
 * ClassName: ProvincePartitioner2
 * Package: com.example.mapreduce.partitionerandwritableComparable
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-07-16
 * Time: 18:41
 */

public class ProvincePartitioner2 extends Partitioner<FlowBean, Text> {

    @Override
    public int getPartition(FlowBean flowBean, Text text, int i) {
        //也是按照手机前三位进行分组
        String phone = text.toString();

        String prePhone = phone.substring(0, 3);

        int partition;

        if ("136".equals(prePhone)) {
            partition =  0;
        } else if ("137".equals(prePhone)) {
            partition =  1;
        } else if ("138".equals(prePhone)) {
            partition =  2;
        } else if ("139".equals(prePhone)) {
            partition =  3;
        } else {
            partition =  4;
        }


        return partition;
    }
}
